package com.itheima.StringTest;

import java.util.Scanner;

public class StringTest1 {
    public static void main(String[] args) {
        //转换为罗马数字
        Scanner sc = new Scanner(System.in);
        String str;
        //判断输入是否合法
       while(true){
           System.out.println("请输入一个字符串");
           str = sc.next();
           boolean checkResult = checkStr(str);
           if(checkResult==true){
               break;
           }else {
               System.out.println("输入有误，请重新输入");
           }
       }
        String result =ToString(str);
        System.out.println(result);
    }

    public static boolean checkStr(String str){
        if (str.length() > 9) {
            return false;
        }
        for (int i = 0; i < str.length(); i++) {
            if (str.charAt(i) < '0' || str.charAt(i) > '9') {
                return false;
            }
        }
        return true;
    }
    public static String ToString(String str1){
        String result="";
        String numLuo[] = {" ","Ⅰ","Ⅱ","Ⅲ","Ⅳ","Ⅴ","Ⅵ","Ⅶ","Ⅷ","Ⅸ",""};
        for (int i = 0; i < str1.length(); i++) {
            result = result + numLuo[str1.charAt(i) - '0'];
        }
        return result;
    }
}
